import request from "@/utils/request";
enum API {
  C1_URL = "/admin/product/getCategory1", //一级分类
  C2_URL = "/admin/product/getCategory2/", //二级分类
  C3_URL = "/admin/product/getCategory3/", //三级分类
  ATTR_URL = "/admin/product/attrInfoList/", //商品基础属性接口
  ADDORUPDATEATTR_URL = "/admin/product/saveAttrInfo", //添加｜修改属性接口的API
  REMOVEATTR_URL = "/admin/product/deleteAttr/", //删除属性
}
import type { ResponseData } from "@/api/user/type";
import type { CategoryData } from "./type";
import type { AttrData } from "./type";
//获取已有商品属性分类1的数据
export const reqC1 = () => {
  return request.get<any, ResponseData<CategoryData[]>>(API.C1_URL);
};
//获取已有商品属性分类2的数据
export const reqC2 = (category1Id: number | string) => {
  return request.get<any, ResponseData<CategoryData[]>>(
    `${API.C2_URL}${category1Id}`
  );
};
//获取已有商品属性分类3的数据
export const reqC3 = (category2Id: number | string) => {
  return request.get<any, ResponseData<CategoryData[]>>(
    `${API.C3_URL}${category2Id}`
  );
};
//获取商品属性与属性值的方法
export const reqAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string
) => {
  return request.get<any, ResponseData<AttrData[]>>(
    `${API.ATTR_URL}${category1Id}/${category2Id}/${category3Id}`
  );
};
//获取添加｜修改属性的数据方法
export const reqAddOrUpdateAttr = (data: AttrData) => {
  return request.post<any, any>(API.ADDORUPDATEATTR_URL, data);
};
//删除某一个属性的方法
export const reqRemoveAttr = (attrId: number | string) => {
  return request.delete<any, any>(`${API.REMOVEATTR_URL}${attrId}`);
};
